using System;
using System.Collections.Generic;
using System.Text;
using DDW.Collections;

namespace DDW
{
	public class DelegateNode : BaseNode
	{
		private Modifier modifiers;
		public Modifier Modifiers
		{
			get { return modifiers; }
			set { modifiers = value; }
		}

		private TypeNode type;
		public TypeNode Type
		{
			get { return type; }
			set { type = value; }
		}

		private IdentifierExpression name;
		public IdentifierExpression Name
		{
			get { return name; }
			set { name = value; }
		}
		
		private NodeCollection<ParamDeclNode> parameters;
		public NodeCollection<ParamDeclNode> Params
		{
			get { if (parameters == null) parameters = new NodeCollection<ParamDeclNode>(); return parameters; }
			set { parameters = value; }
		}

		public override void ToSource(StringBuilder sb)
		{
			if (attributes != null)
			{
				attributes.ToSource(sb);
				this.NewLine(sb);
			}
			TraceModifiers(modifiers, sb);

			sb.Append("delegate ");
			type.ToSource(sb);
			sb.Append(" ");
			name.ToSource(sb);

			sb.Append("(");
			if (parameters != null)
			{
				string comma = "";
				foreach (ParamDeclNode pdn in parameters)
				{
					sb.Append(comma);
					comma = ", ";
					pdn.ToSource(sb);
				}
			}
			sb.Append(");");
			this.NewLine(sb);

		}
	}
}